//
//  MieHuoQiCheckViewController.m
//  Qihuo
//
//  Created by Vencoo on 13-12-31.
//  Copyright (c) 2013年 Vencoo. All rights reserved.
//

#import "MieHuoQiCheckViewController.h"
#import "CarManageCheckCell.h"
@interface MieHuoQiCheckViewController ()
{
    NSMutableArray *_MutableCheckNames;
    NSMutableArray *_checkStatuses;
    NSMutableArray *_remarks;
}
@end

@implementation MieHuoQiCheckViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    if (self.delegate.checkAreaNumber == 4)
    {
        self.checkURL = resultOfMieFireHigh;
        self.title = @"高区消火栓巡检记录";
    }
    else if (self.delegate.checkAreaNumber == 5)
    {
        self.checkURL = resultOfMieFireLower;
        self.title = @"低区消火栓巡检记录";
    }
    self.checkNames = @[@"",@"巡检情况",@"",@"异常情况及报修",@""];
    [super viewDidLoad];
    
    _MutableCheckNames = [NSMutableArray array];
    _remarks = [NSMutableArray array];
    _checkStatuses = [NSMutableArray array];

 }
#pragma mark - UITableViewDataSource
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *identifier = @"cell";
    CarManageCheckCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
    if (!cell)
    {
        cell = [[CarManageCheckCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    if (_MutableCheckNames.count > 0 && [[_MutableCheckNames objectAtIndex:indexPath.section]count] > 0)
    {
        cell.longFloorNameLb.text = [[_MutableCheckNames objectAtIndex:indexPath.section]objectAtIndex:indexPath.row];
    }
    if (_checkStatuses.count > 0 && [[_checkStatuses objectAtIndex:indexPath.section]count] > 0)
    {
        cell.resultLb.text = [[_checkStatuses objectAtIndex:indexPath.section]objectAtIndex:indexPath.row];
    }
    if (_remarks.count > 0 && [[_remarks objectAtIndex:indexPath.section]count] >0)
    {
        cell.processLb.text = [[_remarks objectAtIndex:indexPath.section]objectAtIndex:indexPath.row];
    }
    return cell;
}
#pragma mark - request
- (void)requestDone:(ASIFormDataRequest *)request
{
    [MBProgressHUD hideHUDForView:self.view animated:YES];
    NSString *response = [request responseString];
    NSDictionary *queryDic = [response JSONValue];
    NSDictionary *queryDataArr = [queryDic objectForKey:@"data"];
    NSArray *floorData = [queryDataArr objectForKey:@"floorData"];
    NSLog(@"查询%@",floorData);
    
    if ([[floorData objectAtIndex:0] valueForKey:@"floorName"])
    {
        self.floorNames = [NSMutableArray array];
    }
    for (int i = 0; i < floorData.count; i ++)
    {
        NSDictionary *queryDic = [floorData objectAtIndex:i];
        if ([queryDic objectForKey:@"floorName"]) {
            [self.floorNames addObject:[queryDic valueForKey:@"floorName"]];
        }
        if ([queryDic objectForKey:@"checkData"]) {
            [self.floorCheckDatas addObject:[queryDic valueForKey:@"checkData"]];
        }
    }    
    for (int i = 0; i < self.floorCheckDatas.count; i ++)
    {
        NSArray *floorDatas = [self.floorCheckDatas objectAtIndex:i];
        NSMutableArray *checkName = [NSMutableArray array];
        NSMutableArray *checkStatus = [NSMutableArray array];
        NSMutableArray *remark = [NSMutableArray array];
        for (int j = 0; j < floorDatas.count; j ++)
        {
            NSDictionary *floorDic = [floorDatas objectAtIndex:j];
            [checkName addObject:[floorDic objectForKey:@"checkName"]];
            [checkStatus addObject:[floorDic objectForKey:@"checkStatus"]];
            [remark addObject:[floorDic objectForKey:@"remark"]];
        }
        [_checkStatuses addObject:checkStatus];
        [_MutableCheckNames addObject:checkName];
        [_remarks addObject:remark];
    }
    [self.mainTable reloadData];
}
#pragma mark - end
- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
